<?php
namespace app\web\controller;

use app\common\controller\HomeBase;  // model
use think\Db;                       // db
use app\common\model\Photo as PhotoModel;
use app\common\model\Article as ArticleModel;

class Index extends HomeBase
{
//    private $_photo_model;
    private $_photo_model;
    private $_article_model;
    //

    /*
     * 控制器初始化
     * */
    public function _initialize()
    {
        $this->_photo_model = new PhotoModel();
        $this->_article_model = new ArticleModel();
    }

    /*
     * 相册列表首页
     * */
    public function index($id=0)
    {
//        $re =  $this->_photo_model->showHomeList($id);
//        $this->assign('results',$re);
//        // 这里做图片显示首页, 解析上传的图片数据
//        $this->assign('title','首页');
//        return view('base2');
        $this->redirect('index/index/index');
    }

    /*
     * 前端分页的详情图片
     * */
    public function detail($id){
        if(!empty($id)){
            // get photo array
            $re = $this->_article_model->showOneArticle($id);
            if(is_array($re) && !empty($re)){
                $images_array = $re['0'];

                $photo_str = $images_array['photo'];

                $photo_array = unserialize($photo_str);


                //  $this->assign('photos',$photo_array);

            }else{
                $this->error('错误页面','Index/index');
            }
            $this->assign('images',$images_array);
            $this->assign('photos',$photo_array);
            $this->assign('results',$re);
            return view('detail');


        }else{
//            $this->success('新增成功', 'Article/index');
            $this->error('错误页面','Index/index');
        }

    }

    /*
     * 图片详细列表
     * */
    public function detail_bak($id,$page=1){
        if(!empty($id)){
            // get photo array
            $re = $this->_photo_model->showOneArticle($id);


            if(is_array($re) && !empty($re)){
                $images_array = $re['0'];
                var_dump($images_array);

                $photo_str = $images_array['photo'];

                $photo_array = unserialize($photo_str);

                var_dump($photo_array);

                //  $this->assign('photos',$photo_array);

            }else{
                $this->error('错误页面','Index/index');
            }
            $this->assign('images',$images_array);
            $this->assign('photos',$photo_array);
            $this->assign('results',$re);
            return view('detail');


        }else{
//            $this->success('新增成功', 'Article/index');
            $this->error('错误页面','Index/index');
        }
    }


    /*
     * 其他大类页面
  * @author rose @date 2017 02 25
  * */

    public function cid($cid=0){
        if(!empty($cid)){

            //  return $this->thinkJson($re);
        }else{
//            return $this->thinkJson($id);
            return 'error';
        }
    }



}
